module.exports = {
	 getDayName: function(d){
	   var td=new Date();
	   td=new Date(td.getFullYear(),td.getMonth(),td.getDate());
	   var od=new Date(d);
	   od=new Date(od.getFullYear(),od.getMonth(),od.getDate());
	   var xc=(od-td)/1000/60/60/24;
	   if(xc==0){
	      return "今天";
	   }else if(xc<2){
	      return "明天";
	   }else if(xc<3){
	      return "后天";
	   }else{
	      return (od.getMonth()+1)+"月"+od.getDate()+"日"
	   }
	},
	 // 日期月份/天的显示，如果是1位数，则在前面加上'0'
	getFormatDate: function(arg) {
		if (arg == undefined || arg == '') {
			return '';
		}
		let re = arg + '';
		if (re.length < 2) {
			re = '0' + re;
		}
		return re;
	},
	// 日期，在原有日期基础上，增加days天数，默认增加1天
	addDate: function(datestr, days) {
		if (days == undefined || days == '') {
			days = 1;
		}
        let date = new Date(datestr);
		date.setDate(date.getDate() + days);
		let month = date.getMonth() + 1;
		let day = date.getDate();
		return date.getFullYear() + '-' + this.getFormatDate(month) + '-' + this.getFormatDate(day);
	},
	formatDate: function(date, fmt) {
		if (/(y+)/.test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
		}

		let o = {
			'M+': date.getMonth() + 1,
			'd+': date.getDate(),
			'h+': date.getHours(),
			'm+': date.getMinutes(),
			's+': date.getSeconds()
		};

		for (let k in o) {
			if (new RegExp(`(${k})`).test(fmt)) {
				let str = o[k] + '';
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : this.padLeftZero(str));
			}
		}
		return fmt;
	},
	padLeftZero: function(str) {
		return ('00' + str).substr(str.length);
	},
}


